/**
 * 
 */
package com.zc.BankCreditManagement.Servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.zc.BankCreditManagement.ServiceImpl.DepositDetailsServiceImpl;
import com.zc.BankCreditManagement.JavaBean.DepositDetails;

/**
 * @author ZhangCheng
 * @time 2019年9月25日
 */
@WebServlet("/ManageServlet")
public class ManageServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8968504774619758878L;
	
	public ManageServlet() {
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String type = req.getParameter("Type");
		if("MyDepositManage".equals(type)||"Refresh".equals(type)) {
			sendMsgToHTML(resp, getDepositsByManId(req,resp));
		}
	}
	/**
	 * 	根据经理Id来获取其经手的所有质押物信息
	 * @return ArrayList -> DepositDetails
	 */
	private ArrayList<DepositDetails> getDepositsByManId(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
		int manId = Integer.parseInt(req.getParameter("peoId"));
		DepositDetailsServiceImpl dDSI = new DepositDetailsServiceImpl();
		
		return dDSI.getAllLoaningDepositsByManId(manId);
		
	}
	private void sendMsgToHTML(HttpServletResponse resp, Object obj) throws ServletException, IOException {
		Gson gson = new Gson();
		String msg = gson.toJson(obj);
		resp.setContentType("json/application;charset=UTF-8");
		resp.getWriter().write(msg);
	}
}
